package by.siarhei.java.tij.polymorphism.exercises.ex16;

/**
 * @author Siarhei Shchahratsou <s.siarhei@gmail.com>
 * @since 03.04.2014
 */
public class Starship {
    private AlertStatus status;

    public Starship() {
        this.status = new InfoStatus();
    }

    public void changeToWarn() {
        status = new WarnStatus();
    }

    public void changeToInfo() {
        status = new InfoStatus();
    }

    public void changeToError() {
        status = new ErrorStatus();
    }

    public void showStatus() {
        status.alert();
    }

    public static void main(String[] args) {
        Starship starship = new Starship();
        starship.showStatus();

        starship.changeToWarn();
        starship.showStatus();

        starship.changeToError();
        starship.showStatus();
    }
}

abstract class AlertStatus{
    abstract void alert();
}

class WarnStatus extends AlertStatus {

    @Override
    void alert() {
        System.out.println("warn");
    }
}

class InfoStatus extends AlertStatus {

    @Override
    void alert() {
        System.out.println("info");
    }
}

class ErrorStatus extends AlertStatus {

    @Override
    void alert() {
        System.out.println("error");
    }
}